package com.cdxy.controller;

import com.cdxy.aop.ForceLogin;
import com.cdxy.biz.process.IPasswordOptBizProcess;
import com.cdxy.model.dto.base.controller.BaseController;
import com.cdxy.model.dto.base.resp.ApiResponse;
import com.cdxy.model.dto.req.ForgetPasswordReq;
import com.cdxy.model.dto.req.ModifyPasswordReq;
import com.cdxy.model.dto.req.SendMobileCodeReq;
import com.cdxy.model.dto.req.SetPasswordReq;
import com.cdxy.util.AxUidUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: tangy
 * @Date: 2020/3/10 10:02
 */
@RequestMapping("/passwordOpt")
@Api(tags = "密码操作")
@RestController
public class PasswordOptController extends BaseController {

    @Autowired
    private IPasswordOptBizProcess passwordOptBizProcess;

    @Autowired
    private AxUidUtil axUidUtil;

    @PostMapping("/setPassword")
    @ApiOperation(value = "设置密码", notes = "设置密码")
    @ForceLogin
    public ApiResponse setPassword(@Validated @RequestBody SetPasswordReq setPasswordReq) {
        setPasswordReq.setAxUid(axUidUtil.getAxUid());
        passwordOptBizProcess.setPassword(setPasswordReq);
        return successApiResponse();
    }

    @PostMapping("/sendSmsModifyPassword")
    @ApiOperation(value = "忘记密码发送验证码")
    public ApiResponse sendSmsModifyPassword(@Validated @RequestBody SendMobileCodeReq sendMobileCodeReq) {
        passwordOptBizProcess.sendSmsModifyPassword(sendMobileCodeReq);
        return successApiResponse();
    }

    @PostMapping("/modifyPassword")
    @ApiOperation(value = "修改密码", notes = "")
    @ForceLogin
    public ApiResponse modifyPassword(@Validated @RequestBody ModifyPasswordReq modifyPasswordReq) {
        modifyPasswordReq.setAxUid(axUidUtil.getAxUid());
        passwordOptBizProcess.modifyPassword(modifyPasswordReq);
        return successApiResponse();
    }

    @PostMapping("/sendSmsForgetPassword")
    @ApiOperation(value = "忘记密码发送验证码")
    public ApiResponse sendSmsForgetPassword(@Validated @RequestBody SendMobileCodeReq sendMobileCodeReq) {
        passwordOptBizProcess.sendSmsForgetPassword(sendMobileCodeReq);
        return successApiResponse();
    }

    @PostMapping("/forgetPassword")
    @ApiOperation(value = "忘记密码", notes = "")
    public ApiResponse forgetPassword(@Validated @RequestBody ForgetPasswordReq forgetPasswordReq) {
        passwordOptBizProcess.forgetPassword(forgetPasswordReq);
        return successApiResponse();
    }
}
